<script>
	import {
		mapState,
		mapMutations
	} from 'vuex';
	export default {
		computed: {
			...mapState(['hasLogin'])
		},

		onLaunch: function() {
			console.log('App Launch');
			this.loadSavedUserInfo();
			this.loadSavedMessageList();
			
			const _self = this;
			let _cid = 'by_web_no_cid';
			// #ifdef APP-PLUS
			const clientInfo = plus.push.getClientInfo()
			_cid = clientInfo.clientid;
			console.log("_cid = " + _cid)
			// #endif
			
			
			
			// #ifdef APP-PLUS
			const _handleReceivePush = function(message) {
				console.log("_handleReceivePush -- msg = " + message)
				_self.onReceiveMsg(message)
			};
			const _handleClickPush = function(message) {
				console.log("_handleClickPush -- msg = " + message)
				_self.onClickMsg(message)
			};
			plus.push.addEventListener('click', _handleClickPush);
			plus.push.addEventListener('receive', _handleReceivePush);
			// #endif

		},
		onShow: function() {
			console.log('App Show');
			this.checkLogin();
		},
		onHide: function() {
			console.log('App Hide');
		},

		methods: {
			...mapMutations(['login', 'initMessageList']),
			loadSavedUserInfo() {
				let userInfo = uni.getStorageSync('userInfo');
				// console.log(userInfo)

				if (userInfo != null && userInfo.token != null) {
					//更新登陆状态
					this.login(userInfo);
				}
			},
			
			loadSavedMessageList() {
				this.initMessageList();
			},
			
			checkLogin() {
				// return;
				if(!this.hasLogin) {
					uni.redirectTo({
						url:"/pages/account/login"
					})
				}
			}
		}
	};
</script>

<style>
	/* 解决头条小程序组件内引入字体不生效的问题 */
	/* #ifdef MP-TOUTIAO */
	@font-face {
		font-family: uniicons;
		src: url('/static/uni.ttf');
	}

	/* #endif */

	page {
		height: 100%;
		background-color: #F8F8F8;
	}

	.page-web {
		z-index: 0;
	}
</style>
